import 'package:flutter/material.dart';
import 'package:wanAndroid/widget/LoadMore.dart';

import 'ListBaseWidget.dart';

enum LoadMoreStatus { NONE, END, LOADING, ERROR }

class BaseLoadWidget extends StatefulWidget {
  final BaseLoadState state;
  final LoadCallback loadCallBack; //错误事件处理;
  final LoadMoreStatus loadStatus;

  BaseLoadWidget(
      {Key key,
      this.state,
      this.loadStatus = LoadMoreStatus.NONE,
      this.loadCallBack})
      : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return state != null ? state : new LoadMore(loadCallBack);
  }
}

abstract class BaseLoadState extends State<BaseLoadWidget> {
  LoadMoreStatus status = LoadMoreStatus.NONE;

  @override
  Widget build(BuildContext context) {
    switch (widget.loadStatus) {
      case LoadMoreStatus.ERROR:
        return errorWidget(context);
      case LoadMoreStatus.END:
        return endWidget(context);
      case LoadMoreStatus.LOADING:
        return loadWidget(context);
      default:
        return new Container();
    }
  }

  Widget errorWidget(BuildContext context);

  Widget endWidget(BuildContext context);

  Widget loadWidget(BuildContext context);
}
